﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssemblyInfoEditor.Project
{
    public class ProjectAssemblyInfoCollection : ICollection<ProjectAssemblyInfo>
    {
        protected ArrayList innerList;
        protected bool isReadOnly;

        public ProjectAssemblyInfoCollection()
        {
            innerList = new ArrayList();
            isReadOnly = false;
        }

        public virtual ProjectAssemblyInfo this[int Index]
        {
            get { return (ProjectAssemblyInfo)innerList[Index]; }
            set { innerList[Index] = value; }
        }

        public virtual ProjectAssemblyInfo this[string projectName]
        {
            get
            {
                foreach (ProjectAssemblyInfo pai in innerList)
                {
                    if (pai.Project.Name == projectName)
                    {
                        return pai;
                    }
                }

                return null;
            }
            set
            {
                int index = -1;

                foreach (ProjectAssemblyInfo pai in innerList)
                {
                    if (pai.Project.Name == projectName)
                    {
                        index = innerList.IndexOf(pai);
                    }
                }

                this[index] = value;
            }
        }

        public virtual void Add(ProjectAssemblyInfo item)
        {
            innerList.Add(item);
        }

        public virtual void Clear()
        {
            innerList.Clear();
        }

        public virtual bool Contains(ProjectAssemblyInfo item)
        {
            return innerList.Contains(item);
        }

        public virtual void CopyTo(ProjectAssemblyInfo[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }

        public virtual int Count
        {
            get { return innerList.Count; }
        }

        public virtual bool IsReadOnly
        {
            get { return isReadOnly; }
        }

        public virtual bool Remove(ProjectAssemblyInfo item)
        {
            if (innerList.Contains(item))
            {
                innerList.Remove(item);
                return true;
            }
            else
            {
                return false;
            }
        }

        public virtual IEnumerator<ProjectAssemblyInfo> GetEnumerator()
        {
            return new ProjectAssemblyInfoEnumerator(this);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return new ProjectAssemblyInfoEnumerator(this);
        }
    }
}
